﻿@model IEnumerable<ZdSoft.Model.Course>

@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<p>
    @*@Html.ActionLink("创建课程信息", "Create", new { id = "createCourse" })*@
    <a href="javascript:" id="createCourse">创建课程信息</a>
</p>
<table class="layui-table">
    <thead>
        <tr>

            <th>
                @Html.DisplayNameFor(model => model.CourseName)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.CourseInfo)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.CourseCode)
            </th>
            <th>操作</th>
        </tr>
    </thead>
    <tbody>
        @foreach (var item in Model)
        {
            <tr>

                <td>
                    @Html.DisplayFor(modelItem => item.CourseName)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.CourseInfo)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.CourseCode)
                </td>
                <td>
                    @Html.ActionLink("Edit", "Edit", new { courceID = item.ID }) |
                    @Html.ActionLink("Details", "Details", new { courceID = item.ID }) |
                    @Html.ActionLink("Delete", "Delete", new { courceID = item.ID })
                </td>
            </tr>
        }
    </tbody>
</table>
<div id="page"></div>
<script>

    $(function(){
        $("#createCourse").click(function () {
            //自定页
            layer.open({
                type: 2,
                title: "Online Study System",
                skin: 'demo-class', //样式类名
                offset: "20px",
                closeBtn: 0, //不显示关闭按钮
                shift: 2,
                scrollbar: false,
                resize: false,
                area: ['480px', '620px'], //宽高
                shadeClose: false, //开启遮罩关闭
                fixed: true,
                content: ["http://localhost:24833/Course/Create", 0]
            });
        });

        //a标签的信息，要是是删除或者修改则需要提示
        $("a").click(function () {
            switch ($(this).text().trim()) {
                case "Edit":
                    return confirm("你确认修改吗？"); break;
                case "Delete":
                    return confirm("你确认删除吗？"); break;
                default:
                    break;
            }
        });

        //分页模块

        layui.use('laypage', function () {
            var laypage = layui.laypage;

            //执行一个laypage实例
            laypage.render({
                elem: 'page' //注意，这里的 test1 是 ID，不用加 # 号
              , count: @ViewBag.courseCount  //数据总数，从服务端得到@ViewBag.resourseCount
              , layout: ['count', 'prev', 'page', 'next', 'skip']
              , jump: function (obj,first) {
                  if(!first){
                      $.post("../Course/Index",{pageSize:obj.limit,pageIndex:obj.curr},function(data){
                          //console.log(data);
                          $("tbody").html("");
                          $.each($.parseJSON(data),function(index,obj){
                              var tbodyhtm="<tr>"+
                              "<td>"+
                                  obj.CourseName+
                              "</td>"+
                              "<td>"+
                                  obj.CourseInfo+
                              "</td>"+
                              "<td>"+
                                  obj.CourseCode+
                              "</td>"+
                              "<td>"+
                                  "<a href='/User/Edit?resourceID="+obj.ID+"'>Edit</a>"+"|"+
                                  "<a href='/User/Details?resourceID="+obj.ID+"'>Details</a>"+"|"+
                                  "<a href='/User/Delete?resourceID="+obj.ID+"'>Delete</a>"+
                              "</td>"+
                          "</tr>";
                              $("tbody").append(tbodyhtm);
                          });
                      });
                  }
              }
            });
        });
    });


</script>